<?php
namespace app\index\controller;

use think\Db;
use think\Request;

class Question
{
    // 入口
    public function index()
    {
        return ['data'=>'欢迎来到api.vchao.top','code'=>1,'message'=>'操作完成'];
    }

    // 获取某道题目具体信息
    public function info()
    {
        if (request()->isPost()) {
            $request = Request::instance();
            $car_id = $request->param('q_id');
            
            $res = Db::table('question')
                    ->where('q_id','=',$car_id)
                    ->find();
            return ['code'=>1,'message'=>'操作完成','data'=>$res];
        }
    }

    // 获取题目列表
    public function list()
    {
        if (request()->isPost()) {
            $request = Request::instance();
            // 题目数量
            $number = $request->param('number');
            // 题目类型 [0选择 1判断 2问答]
            $q_type = $request->param('type');
            
            $res = Db::table('question')
                    ->where('q_type','=',$q_type)
                    ->limit($number)
                    ->select();
            return ['code'=>1,'message'=>'操作完成','data'=>$res];
        }
    }
}
